package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @Description: 公用常量
 * @Data: 2022/9/8 16:13
 * @Pacakge: com.qf.controller
 * @ClassName: ThymeleafController
 * @Author: fan
 */
@Controller
public class ThymeleafController {
    @RequestMapping("aa")
    public String aa(){
        System.out.println("aa执行了...");
        return "aa";
    }
    @RequestMapping("user")
    @ResponseBody
    public String getUser(Integer id,String name){
        System.out.println("getUser执行了....");
        System.out.println("id="+id);
        System.out.println("name = " + name);
        return "id:"+id+"\n name:"+name;
    }
    @RequestMapping("thymeleaf")
    public String getMessage(Model model){
        System.out.println("getMessages执行了");
        model.addAttribute("msg","你好,SpringBoot");
        model.addAttribute("username","小樊");
        model.addAttribute("birthday","1997-10-14");
        return "messages";
    }
    @RequestMapping("myThymeleaf")
    public String myThymeleaf(){
        System.out.println("myThymeleaf执行了");
        return "thymeleaf";
    }
    @RequestMapping("bb")
    public String bb(Model model){
        model.addAttribute("msg","小小");
        model.addAttribute("birthday",new Date());
        model.addAttribute("sex",'男');
        System.out.println("运行了nnController");

        List<User> list = new ArrayList<>();
        for (int i= 0;i<5;i++){
            list.add(new User(i,"number"+i,new Date(),"10"+i));
        }
        model.addAttribute("userList",list);
        return "thymeleaf";
    }
}
